import sys,os

myDict= {'107650':'ZeeNp0','107651':'ZeeNp1','107652':'ZeeNp2','107653':'ZeeNp3','107654':'ZeeNp4','107655':'ZeeNp5','109300':'ZeebbNp0','109301':'ZeebbNp1','109302':'ZeebbNp2','109303':'ZeebbNp3','126414':'ZeeccNp0','126415':'ZeeccNp1','126416':'ZeeccNp2','126417':'ZeeccNp3'}

evgenDict = {}
aodDict  = {}
#get files. 
for j in jobs:
    if("evgen" in j.name): 
        evgenDict[j.name[14:20]] = j.outputdata.datasetname
    if("AOD" in j.name):
        aodDict[j.name[14:20]] = j.outputdata.datasetname


outDict_evgen = dict([(val1, val2) for key1,val1 in myDict.iteritems() for key2,val2 in evgenDict.iteritems() if key1 == key2])
outDict_aod   = dict([(val1, val2) for key1,val1 in myDict.iteritems() for key2,val2 in aodDict.iteritems() if key1 == key2])


f1 = open("dq2commands_evgen.sh","w")
f2 = open("dq2commands_aod.sh","w")

for dir,ds in outDict_evgen.iteritems():
    s = '(mkdir -p ' + str(dir) + ';' + 'cd ' + str(dir) + ';' + 'dq2-get -f \\*root\\* ' + str(ds) + ')\n'
    f1.write(s)

for dir,ds in outDict_aod.iteritems():
    s = '(mkdir -p ' + str(dir) + ';' + 'cd ' + str(dir) + ';' + 'dq2-get -f \\*root\\* ' + str(ds) + ')\n'
    f2.write(s)


f1.close()
f2.close()
